/**
 * com.monte.persistence.command.MyBatisSelectOneCommand.java
 * create by FengMy from 2013
 */
package com.monte.persistence.command;

import com.monte.persistence.CommandContext;
import com.monte.persistence.PersistenceCommand;
import com.monte.util.StringUtils;

/**
 * @描述: mybatis查询单一结果
 * @author FengMy
 * @since 2013-3-21
 */
public class MyBatisSelectOneCommand<T> implements PersistenceCommand {
	private String mapper;
	private Object param;
	public MyBatisSelectOneCommand(String mapper, Object param){
		if(StringUtils.isEmpty(mapper)){
			throw new IllegalArgumentException("mybatis mapper could not to be empty");
		}
		this.mapper = mapper;
		this.param = param;
	}
	@SuppressWarnings("unchecked")
	@Override
	public T execute(CommandContext context) {
		return (T) context.getSqlSession().selectOne(mapper, param);
	}

}
